from django.db import models

# Create your models here.
class Author1(models.Model):
    """作者表"""
    name = models.CharField(max_length=10, verbose_name='作者名字')
    age = models.IntegerField(default=1, verbose_name='年龄')
    dates = models.DateTimeField(auto_now=True, verbose_name="添加时间")
    
    def __str__(self) -> str:
        return f"作者: {self.name}, 年龄: {self.age}, 添加时间: {self.dates}"
    
    
    class Meta:
        db_table = 'Author1'
        # managed = True
        verbose_name = '作者表(Author1)'
        verbose_name_plural = '作者表(Author1)'
        
        
class Book1(models.Model):
    """书籍表"""
    name = models.CharField(max_length=10, verbose_name='书籍名字')
    dates = models.DateTimeField(auto_now=True, verbose_name="添加时间")
    # 添加外链, 多对多
    authors = models.ManyToManyField(Author1, verbose_name='多,作者(外链)')
    
    def __str__(self) -> str:
        return f"书籍名: {self.name}, 添加时间: {self.dates}, 多,作者(外链): {self.authors}"
    
    
    class Meta:
        db_table = 'Book1'
        # managed = True
        verbose_name = '书籍表(Book1)'
        verbose_name_plural = '书籍表(Book1)'